<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <el-form ref="elForm"    size="small" :disabled="true" label-width="120px">
      <el-row type="flex" justify="start" align="top"  >
        <el-form-item label="村数量" prop="villageNum">
          <el-input v-model="dataWgWgCj.villageNum"  placeholder="" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
        <el-form-item label="总户数" prop="zhs">
          <el-input   v-model="dataWgWgCj.zhs" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="存款家庭户数" prop="ckhs">
          <el-input   v-model="dataWgWgCj.ckhs" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
        <el-form-item label="存款金额" prop="ckye">
          <el-input   v-model="dataWgWgCj.ckje" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="贷款户数" prop="dkhs">
          <el-input   v-model="dataWgWgCj.dkhs" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="贷款余额" prop="dkye">
          <el-input   v-model="dataWgWgCj.dkye" :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-row>
      <el-row type="flex" justify="start" align="top"  >
        <el-form-item label="电银产品数" prop="dzyhgs">
          <el-input   v-model="dataWgWgCj.dzyhgs" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
        <el-form-item label="家庭产品覆盖面" prop="productCoverage">
          <el-input   v-model="dataWgWgCj.productCoverage" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="有效家庭覆盖面" prop="familyCoverage">
          <el-input   v-model="dataWgWgCj.familyCoverage" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
        <el-form-item label="授信金额" prop="sxje">
          <el-input   v-model="dataWgWgCj.sxje" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="授信签约率" prop="sxqyl">
          <el-input   v-model="dataWgWgCj.sxqyl" :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-row>
    </el-form>

    <el-table v-loading="loading" :data="gridCJList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="户主姓名" align="center" prop="hzxm">
        <template slot-scope="scope">
          <router-link :to="{path:'/cj/cjfamily/',query: {cjhZbh: scope.row.hjbh}}" class="link-type">
            <span>{{ scope.row.hzxm }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="户籍编号" width="180" align="center" prop="hjbh"/>
      <el-table-column label="总人数" align="center" prop="rs"/>
      <el-table-column label="存款金额" align="center" prop="ckje" />
      <el-table-column label="存款年日均" width="180" align="center" prop="cknrj"  />
      <el-table-column label="贷款余额" align="center" prop="dkye"  />
      <el-table-column label="社保卡人数" align="center" prop="sbkrs"  />
      <!-- <el-table-column label="外地打工人数" width="180" align="center" prop="workRs" /> -->
      <el-table-column label="电银产品数" align="center" prop="dzyhgs"  />
      <!-- <el-table-column label="土地亩数" align="center" prop="land"  /> -->
      <!-- <el-table-column label="流转土地亩数" align="center" prop="lzLand" /> -->
      <!-- <el-table-column label="养殖土地亩数" align="center" prop="breedLand"  /> -->
      <!-- <el-table-column label="种植土地亩数" align="center" prop="plantLand"  /> -->
      <el-table-column label="五星客户数" align="center" prop="fiveStart"  />
      <el-table-column label="四星客户数" align="center" prop="fourStart"  />
      <el-table-column label="三星客户数" align="center" prop="threeStart"  />
      <el-table-column label="二星客户数" align="center" prop="twoStart"  />
      <el-table-column label="一星客户数" align="center" prop="oneStart"  />
      <el-table-column label="人均存款金额" align="center" prop="rjckje" />
      <el-table-column label="人均贷款金额" align="center" prop="rjdkye"  />
      <el-table-column label="人均电银产品数" align="center" prop="rjdzyhgs"  />
      <el-table-column label="村名称" align="center" prop="village"  />
      <el-table-column label="机构" align="center" prop="orgId"  />

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改网格商户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGridCJ, gridCJVillageList } from "@/api/buss/gridCJ";

export default {
  name: "GridSh",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 网格商户表格数据
      gridCJList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 机构号字典
      orgIdOptions: [],

      userIdOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        road: null,
        coordinate: null,
        shopName: null,
        regName: null,
        zjhm: null,
        phone: null,
        managerName: null,
        address: null,
        orgId: null,
        temp: null,
        tempId: null,
        lat: null,
        lng: null,
        userId: null,
        shmt: null,
        shzcmc: null,
        jyfw: null,
        jydz: null,
        fddbr: null,
        fddbrzjhm: null,
        sjjyr: null,
        sjjyrzjhm: null,
        khdj: null,
        group: null,
        khlx: null,
        jyzk: null,
        cpbq: null,
        sshy: null,
        sfyxsh: null,
        amount: null,
        isExpand: null,
        sfyxzj: null,
        remark: null,
        delFlag: null,
        createUser: null,
        updateUser: null,
        updateTime: null,
        createTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      dataWgWgCj: {},
      queryCJ: {
        village: '',
        orgId: ''
      }
    };
  },
  created() {

    const cjhZ = this.$route.query.cjhZ;
    const cjhZorgId = this.$route.query.cjhZorgId;
    this.queryCJ.village = cjhZ;
    this.queryCJ.orgId = cjhZorgId;
    this.getDicts("sys_org_id").then(response => {
      this.orgIdOptions = response.data;
    });
    this.getList();
    this.getDicts("sys_user_id").then(response => {
      this.userIdOptions = response.data;
    });
  },
  methods: {
    /** 查询网格商户列表 */
    getList() {
      this.loading = true;
      gridCJVillageList(this.queryCJ).then(response => {
        this.gridCJList = response.data.pageCommonVO.rows;
        this.dataWgWgCj = response.data.gridSurvey;
        this.total = response.data.pageCommonVO.total;
        this.loading = false;
      });
    },
    // 修改时间字典翻译
    idFormat(row, column) {
      return this.selectDictLabel(this.idOptions, row.id);
    },
    // 1区域划分匹配上2手动划分指定客户经理 5手动导入坐标未匹配客户经理 3手动导入坐标后并匹配客户经理字典翻译
    roadFormat(row, column) {
      return this.selectDictLabel(this.roadOptions, row.road);
    },
    // 坐标字典翻译
    coordinateFormat(row, column) {
      return this.selectDictLabel(this.coordinateOptions, row.coordinate);
    },
    // 店铺名称字典翻译
    shopNameFormat(row, column) {
      return this.selectDictLabel(this.shopNameOptions, row.shopName);
    },
    // 注册名字典翻译
    regNameFormat(row, column) {
      return this.selectDictLabel(this.regNameOptions, row.regName);
    },
    // 证件号码字典翻译
    zjhmFormat(row, column) {
      return this.selectDictLabel(this.zjhmOptions, row.zjhm);
    },
    // 电话号码字典翻译
    phoneFormat(row, column) {
      return this.selectDictLabel(this.phoneOptions, row.phone);
    },
    // 客户经理名称字典翻译
    managerNameFormat(row, column) {
      return this.selectDictLabel(this.managerNameOptions, row.managerName);
    },
    // 地址字典翻译
    addressFormat(row, column) {
      return this.selectDictLabel(this.addressOptions, row.address);
    },
    // 机构号字典翻译
    orgIdFormat(row, column) {
      return this.selectDictLabel(this.orgIdOptions, row.orgId);
    },
    // 路段前缀字典翻译
    tempFormat(row, column) {
      return this.selectDictLabel(this.tempOptions, row.temp);
    },
    // 路段前缀ID字典翻译
    tempIdFormat(row, column) {
      return this.selectDictLabel(this.tempIdOptions, row.tempId);
    },
    // 经度字典翻译
    latFormat(row, column) {
      return this.selectDictLabel(this.latOptions, row.lat);
    },
    // 纬度字典翻译
    lngFormat(row, column) {
      return this.selectDictLabel(this.lngOptions, row.lng);
    },
    // 客户经理ID字典翻译
    userIdFormat(row, column) {
      return this.selectDictLabel(this.userIdOptions, row.userId);
    },
    // 商户门口字典翻译
    shmtFormat(row, column) {
      return this.selectDictLabel(this.shmtOptions, row.shmt);
    },
    // 商户注册名称字典翻译
    shzcmcFormat(row, column) {
      return this.selectDictLabel(this.shzcmcOptions, row.shzcmc);
    },
    // 经营范围字典翻译
    jyfwFormat(row, column) {
      return this.selectDictLabel(this.jyfwOptions, row.jyfw);
    },
    // 经营地址字典翻译
    jydzFormat(row, column) {
      return this.selectDictLabel(this.jydzOptions, row.jydz);
    },
    // 法定代表人字典翻译
    fddbrFormat(row, column) {
      return this.selectDictLabel(this.fddbrOptions, row.fddbr);
    },
    // 法定代表证件字典翻译
    fddbrzjhmFormat(row, column) {
      return this.selectDictLabel(this.fddbrzjhmOptions, row.fddbrzjhm);
    },
    // 实际经营人姓名字典翻译
    sjjyrFormat(row, column) {
      return this.selectDictLabel(this.sjjyrOptions, row.sjjyr);
    },
    // 实际经营人证件字典翻译
    sjjyrzjhmFormat(row, column) {
      return this.selectDictLabel(this.sjjyrzjhmOptions, row.sjjyrzjhm);
    },
    // 客户等级字典翻译
    khdjFormat(row, column) {
      return this.selectDictLabel(this.khdjOptions, row.khdj);
    },
    // 客户群体字典翻译
    groupFormat(row, column) {
      return this.selectDictLabel(this.groupOptions, row.group);
    },
    // 客户类型字典翻译
    khlxFormat(row, column) {
      return this.selectDictLabel(this.khlxOptions, row.khlx);
    },
    // 1正常、0关闭、2其他字典翻译
    jyzkFormat(row, column) {
      return this.selectDictLabel(this.jyzkOptions, row.jyzk);
    },
    // 产品标签字典翻译
    cpbqFormat(row, column) {
      return this.selectDictLabel(this.cpbqOptions, row.cpbq);
    },
    // 1餐饮、2住宿、3商超零售、4水产批发、5汽车服务、6居民服务、7其他字典翻译
    sshyFormat(row, column) {
      return this.selectDictLabel(this.sshyOptions, row.sshy);
    },
    // 是否有效商户 0否  1是字典翻译
    sfyxshFormat(row, column) {
      return this.selectDictLabel(this.sfyxshOptions, row.sfyxsh);
    },
    // 预授信额度字典翻译
    amountFormat(row, column) {
      return this.selectDictLabel(this.amountOptions, row.amount);
    },
    // 是否拓展客户 0否 1是字典翻译
    isExpandFormat(row, column) {
      return this.selectDictLabel(this.isExpandOptions, row.isExpand);
    },
    // 是否有效证件字典翻译
    sfyxzjFormat(row, column) {
      return this.selectDictLabel(this.sfyxzjOptions, row.sfyxzj);
    },
    // 备注字典翻译
    remarkFormat(row, column) {
      return this.selectDictLabel(this.remarkOptions, row.remark);
    },
    // 0正常  1已删除字典翻译
    delFlagFormat(row, column) {
      return this.selectDictLabel(this.delFlagOptions, row.delFlag);
    },
    // 创建人字典翻译
    createUserFormat(row, column) {
      return this.selectDictLabel(this.createUserOptions, row.createUser);
    },
    // 修改人字典翻译
    updateUserFormat(row, column) {
      return this.selectDictLabel(this.updateUserOptions, row.updateUser);
    },
    // 创建时间字典翻译
    updateTimeFormat(row, column) {
      return this.selectDictLabel(this.updateTimeOptions, row.updateTime);
    },
    // 修改时间字典翻译
    createTimeFormat(row, column) {
      return this.selectDictLabel(this.createTimeOptions, row.createTime);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        road: null,
        coordinate: null,
        shopName: null,
        regName: null,
        zjhm: null,
        phone: null,
        managerName: null,
        address: null,
        orgId: null,
        temp: null,
        tempId: null,
        lat: null,
        lng: null,
        userId: null,
        shmt: null,
        shzcmc: null,
        jyfw: null,
        jydz: null,
        fddbr: null,
        fddbrzjhm: null,
        sjjyr: null,
        sjjyrzjhm: null,
        khdj: null,
        group: null,
        khlx: null,
        jyzk: null,
        cpbq: null,
        sshy: null,
        sfyxsh: null,
        amount: null,
        isExpand: null,
        sfyxzj: null,
        remark: null,
        delFlag: null,
        createUser: null,
        updateUser: null,
        updateTime: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加网格商户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGridSh(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改网格商户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGridSh(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGridSh(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除网格商户编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delGridSh(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('buss/gridSh/export', {
        ...this.queryParams
      }, `buss_gridSh.xlsx`)
    }
  }
};
</script>
